﻿namespace Hainet

open SdlDotNet.Graphics

module Room =

    type Room() =
        let background = new Surface("background.png")
        
        let objects = new System.Collections.Generic.List<Object.Active>()
        
        member this.Background = background
        member this.Width = float background.Width * 1.0<Pixel>
        member this.Height = float background.Height * 1.0<Pixel>
        
        member this.Add obj =
            objects.Add(obj)
            
        member this.Step() =
            for obj in objects do
                obj.Step()
                match obj.Position.X with
                | x when x < 0.0<_> -> obj.OnIntersectBoundary(Left)
                | x when x > this.Width -> obj.OnIntersectBoundary(Right)
                | _ -> ()
                
                match obj.Position.Y with
                | y when y < 0.0<_> -> obj.OnIntersectBoundary(Top)
                | y when y > this.Height -> obj.OnIntersectBoundary(Bottom)
                | _ -> ()
        
        member this.OnDraw(screen: Surface) =
            ignore <| screen.Blit(background)
            for obj in objects do
                obj.Sprite.X <- int obj.Position.X
                obj.Sprite.Y <- int obj.Position.Y
                ignore <| screen.Blit(obj.Sprite)
            screen.Update()
            
                
